<template>
    <h1>登录</h1>
    <h3>异步接口请求</h3>
    <van-button type="success" @click="onLogin">发送接口请求</van-button>
</template>

<script setup>
const { proxy } = getCurrentInstance();

const state = reactive({
    mobile:'13800000000',
    password:'123'
});

// 请求事件
const onLogin = async () => {

    // 封装数据
    let data = {
        mobile:state.mobile,
        password:state.password
    }

    // 发起请求
    let result = await proxy.$http.post('/business/login',data);

    if(result.code === 1)
    {
        // console.log(result.msg,result.data);

        // 保留登录信息
        // proxy.$business.value = result.data

        // proxy.$store.business = result.data;

        proxy.$store.$patch({
            business:result.data
        });

        proxy.$router.push('/business');
    }else{
        console.log(result.msg);
    }
}
</script>